package com.woniuxy.student.consumer;

import com.rabbitmq.client.Channel;
import com.woniuxy.student.service.AnswerSheetService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date;

/**
 * @Author: 曾令忠
 * @Description: 处理延时队列消息
 * @Date: 2020/7/30 0030-下午 12:15
 */
@Component
public class SubmitConsumer {
    @Resource
    AnswerSheetService answerSheetService;
    @RabbitListener(queues = "delayPluginQueue")
    public void receive(Message msg, Channel channel) throws IOException {
        System.out.println("消费者接收到消息："+new String(msg.getBody())+new Date());
        answerSheetService.insertAnswerSheet(new String(msg.getBody()));
        channel.basicAck(msg.getMessageProperties().getDeliveryTag(),false);
    }
}
